<template>
    <div>
<!--        <div class="crumbs">-->
<!--            <el-breadcrumb separator="/">-->
<!--                <el-breadcrumb-item><i class="el-icon-setting"></i> 设备管理</el-breadcrumb-item>-->
<!--            </el-breadcrumb>-->
<!--        </div>-->
            <div class="container" style="justify-content: space-between;min-height: 800px;">
                <el-row :gutter="20">
                    <el-col :xs="24" :sm="24" :md="5" :lg="5">
                        <div class="l-left" style="height:auto;border: 1px solid #eee;">
                            <div style="line-height: 60px;font-size: 18px;font-weight:500;border-bottom: 1px dashed #eee;">
                                <i class="el-icon-menu"/>组织机构
                            </div>
                                <el-tree
                                        :data="tagsList"
                                        :props="props"
                                        :load="loadNode"
                                        highlight-current
                                        lazy
                                        @node-click="handleNodeClicks"
                                        @node-expand="handleNodeClicks"
                                        ref="tree"
                                        node-key="id">

                                </el-tree>
                        </div>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="19" :lg="19">
                        <div class="content-show" style="border: 1px solid #eee;">
                        <div style="line-height: 60px;font-size: 18px;font-weight:500;border-bottom: 1px dashed #eee;"><i class="el-icon-menu"/>设备列表</div>
                        <div class="handle-box" style="margin:10px 10px;">
    <!--                        <el-button type="success" @click="seach" plain>查询</el-button>-->
                            <!--<el-button type="success" @click="seachEquiment" plain>高级查询</el-button>-->
                            <el-button type="primary" @click="addEquiment">新增</el-button>
                            <el-button type="success" @click="editEquiment">修改</el-button>
                            <!--<el-button @click="editEquimentAll">批量修改</el-button>-->
                            <!--<el-button type="warning" @click="enable">启用</el-button>-->
                            <!--<el-button type="info" @click="disEnable">禁用</el-button>-->
                            <el-button type="danger" @click="deleteAble">删除</el-button>
                            <!--<el-button type="primary" @click="configMid">配置中继链路</el-button>-->
                            <!--<el-button type="danger" @click="configMid('-1')">解除中继链路</el-button>-->
                            <!--<el-button type="primary" @click="reInput">数据补录</el-button>-->
                        </div>
                        <el-table
                                :data="tableData"
                                border
                                expand-on-click-node
                                stripe class="table"
                                @selection-change="handleSelectionChange"
                                ref="multipleTable"
                                style="width: 100%">
                            <el-table-column type="selection" width="55" align="center"></el-table-column>
                            <el-table-column
                                    prop="deviceTypeName"
                                    label="设备类型"
                                    align="center"
                                   >
                            </el-table-column>
                            <el-table-column
                                    prop="deviceName"
                                    label="设备名称"
                                    align="center">
                            </el-table-column>
                            <el-table-column
                                    prop="deviceCode"
                                    label="IMEI"
                                    align="center">
                            </el-table-column>
                            <!--<el-table-column-->
                                <!--prop="deviceUsingState"-->
                                <!--label="设备状态"-->
                                <!--align="center"-->
                                <!--:formatter="formmaterStatas">-->
                        <!--</el-table-column>-->
                            <!--<el-table-column-->
                                    <!--prop="concentratorName"-->
                                    <!--label="所属网关"-->
                                    <!--align="center"-->
                                    <!--&gt;-->
                            <!--</el-table-column>-->
                            <!--<el-table-column-->
                                    <!--prop="repeaterInfo"-->
                                    <!--label="链路名称"-->
                                    <!--align="center"-->
                            <!--&gt;-->
                            <!--</el-table-column>-->
                            <!--<el-table-column-->
                                        <!--prop="dataPara"-->
                                        <!--label="互感比"-->
                                        <!--align="center"-->
                            <!--:formatter="formatRation">-->
                            <!--</el-table-column>-->
                            <!--<el-table-column-->
                                    <!--prop="deviceGroupName"-->
                                    <!--label="设备组"-->
                                    <!--align="center"-->
                                   <!--&gt;-->
                            <!--</el-table-column>-->
    <!--                        <el-table-column-->
    <!--                                prop="energyTypeName"-->
    <!--                                label="能耗类型"-->
    <!--                                align="center"-->
    <!--                                >-->
    <!--                        </el-table-column>-->
                            <el-table-column
                                    prop="deviceLocation"
                                    label="设备位置"
                                    align="center" width="300px">
                            </el-table-column>
                         </el-table>
                        <div class="pagination">
                            <el-pagination background @current-change="handleCurrentChange" layout="prev, pager, next" :total="page_total" :page-size="page_size">
                            </el-pagination>
                        </div>
                    </div>
                    </el-col>
                </el-row>
            </div>
        <!--新增-->
        <el-dialog :title="diologTitle" :close-on-click-modal="$modelGolbParam.closeOnClickModal"
                   :close-on-press-escape="$modelGolbParam.closeOnPressEscape" :visible.sync="addVisible" width="70%">
            <div style="height:auto;overflow: auto;">
            <el-form :model="form"  ref="Form" label-width="120px" class="limit-small" :rules="rules">
                <el-form-item label="组织机构" class="limit-width active" prop="organ">
                         <!--<el-input v-model="form.organ"  :disabled="true"></el-input>-->
                     <el-select v-model="form.organ" clearable placeholder="请选择">
                         <el-option
                                 :value="tagsList">
                             <el-tree
                                     :data="tagsList"
                                     :props="props"
                                     :load="loadNode"
                                     highlight-current
                                     lazy
                                     @node-click="handleNodeClick"
                                     @node-expand="handleNodeClick"
                                     ref="tree"
                                     node-key="id">

                             </el-tree>
                         </el-option>
                     </el-select>
                 </el-form-item>
                <el-form-item v-if="!isEditInfoAll" label="IMEI" class="limit-width active" prop="code">
                    <el-input v-model="form.code"></el-input>
                </el-form-item >
                <el-form-item v-if="!isEditInfoAll" label="设备名称" class="limit-width active" prop="name">
                    <el-input class="el_input form_wid"  v-model="form.name"></el-input>
                </el-form-item >
                <!--<el-form-item v-if="!isEditInfoAll" label="序号(MB偏移)" class="limit-width active" prop="order">-->
                    <!--<el-input class="el_input form_wid"  v-model="form.order" prop="order"></el-input>-->
                <!--</el-form-item>-->
                <!--<el-form-item label="网关" class="limit-width active" prop="concentrator">-->
                    <!--<el-select v-model="form.concentrator"  placeholder="请选择" >-->
                        <!--<el-option-->
                                <!--v-for="item in selectConcentrator"-->
                                <!--:key="item.deviceId"-->
                                <!--:label="item.deviceName"-->
                                <!--:value="parseInt(item.deviceId)">-->
                        <!--</el-option>-->
                    <!--</el-select>-->
                <!--</el-form-item>-->
                <el-form-item v-if="!isEditInfoAll" label="设备类型" class="limit-width active" prop="type" >
                        <el-select v-model="form.type"  placeholder="请选择" @change="selectedDeviceType">
                            <el-option
                                    v-for="item in selectType"
                                    :key="item.typeId"
                                    :label="item.typeName"
                                    :value="parseInt(item.typeId)">
                            </el-option>
                        </el-select>
                </el-form-item>
                <!--<el-form-item label="设备组" class="limit-width active" prop="equipmentGroup">-->
                    <!--<el-select v-model="form.equipmentGroup"  placeholder="请选择">-->
                        <!--<el-option-->
                                <!--v-for="item in selectEqimentGroup"-->
                                <!--:key="item.id"-->
                                <!--:label="item.groupName"-->
                                <!--:value="parseInt(item.id)">-->
                        <!--</el-option>-->
                    <!--</el-select>-->
                <!--</el-form-item>-->
                <!--<el-form-item label="能源来源" class="limit-width active" prop="energyource">-->
                    <!--<el-select v-model="form.energyource"  placeholder="请选择">-->
                        <!--<el-option-->
                                <!--v-for="item in selectEnergySource"-->
                                <!--:key="item.value"-->
                                <!--:label="item.name"-->
                                <!--:value="parseInt(item.value)">-->
                        <!--</el-option>-->
                    <!--</el-select>-->
                <!--</el-form-item>-->
                <!--<el-form-item v-if="!isEditInfoAll" label="能耗类型" class="limit-width active" prop="energType">-->
                         <!--<el-select v-model="form.energType"  placeholder="请选择" @change="handleEnergyType">-->
                             <!--<el-option-->
                                     <!--v-for="item in selectenergType"-->
                                     <!--:key="item.id"-->
                                     <!--:label="item.name"-->
                                     <!--:value="parseInt(item.id)">-->
                             <!--</el-option>-->
                         <!--</el-select>-->
                     <!--</el-form-item>-->
                <!--<el-form-item label="设备状态" class="limit-width active" prop="equimentState">-->
                    <!--<el-select v-model="form.equimentState"   placeholder="请选择">-->
                        <!--<el-option-->
                                <!--v-for="item in selectEquimentState"-->
                                <!--:key="item.value"-->
                                <!--:label="item.label"-->
                                <!--:value="item.value">-->
                        <!--</el-option>-->
                    <!--</el-select>-->
                <!--</el-form-item>-->
                <el-form-item label="设备位置" class="limit-width active" prop="address">
                    <el-input v-model="form.address"  :disabled="true"></el-input>
                </el-form-item >
            </el-form>
            <!-- <div v-if="dataConfigTable.length>1"> 数据项多个的时候显示-->
            <!--<div v-if="!isEditInfoAll">-->
                <!--<template>-->
                    <!--<div>配置数据参数</div>-->
                    <!--<el-table :data="dataConfigTable" border stripe style="width: 100%">-->
                        <!--<el-table-column prop="dataName" label="数据项名称"></el-table-column>-->
                        <!--<el-table-column prop="dataUnit" label="单位"></el-table-column>-->
                        <!--<el-table-column prop="virtualCode" label="虚拟表号">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.virtualCode" size="mini" placeholder="虚拟表号"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                        <!--<el-table-column prop="dataRange" label="量程">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.dataRange" size="mini" placeholder="量程"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                        <!--<el-table-column prop="dataRatio" label="互感比">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.dataRatio" size="mini" placeholder="互感比"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                        <!--<el-table-column prop="dataInitialValue" label="初始读数">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.dataInitialValue" size="mini" placeholder="初始读数"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                        <!--<el-table-column prop="alarmMinValue" label="报警下限">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.alarmMinValue" size="mini" placeholder="报警下限"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                        <!--<el-table-column prop="alarmMaxValue" label="报警上限">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.alarmMaxValue" size="mini" placeholder="报警上限"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                        <!--<el-table-column prop="dataMutationAlarmRegion" label="突变范围">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.dataMutationAlarmRegion" size="mini" placeholder="突变范围"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                    <!--</el-table>-->
                <!--</template>-->
            <!--</div>-->
            <!--<div v-if="!isEditInfoAll">-->
                <!--<template>-->
                    <!--<div>配置能耗比例</div>-->
                    <!--<el-table :data="configEnergyRatio" border stripe style="width: 100%">-->
                        <!--<el-table-column prop="name" label="设备用途"></el-table-column>-->

                        <!--<el-table-column prop="percentData" label="分配比例(%)">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-input class="no-border-input" v-model="scope.row.percentData" size="mini" placeholder="0"></el-input>-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                        <!--<el-table-column prop="remark" label="备注"></el-table-column>-->
                    <!--</el-table>-->
                <!--</template>-->
            <!--</div>-->
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addVisible = false">取 消</el-button>
                <el-button type="primary" @click="save">确 定</el-button>
            </span>
        </el-dialog>
        <!--高级查询-->
        <el-dialog :title="diologTitle" :close-on-click-modal="$modelGolbParam.closeOnClickModal"
                   :close-on-press-escape="$modelGolbParam.closeOnPressEscape" :visible.sync="seachVisible" width="70%">
            <el-form :model="form"  ref="Form" label-width="120px" class="limit-small" :rules="rules">
<!--                <el-form-item label="组织机构" class="limit-width" prop="organ">-->
<!--                    <el-input v-model="form.organ"></el-input>-->
<!--                </el-form-item>-->
                <el-form-item label="设备位置" class="limit-width active" prop="organ">
                    <el-input v-model="form.address"></el-input>
                    <!--<el-select v-model="form.organ" clearable placeholder="请选择">-->
                        <!--<el-option-->
                               <!--:value="tagsList">-->
                            <!--<el-tree-->
                                    <!--:data="tagsList"-->
                                    <!--:props="props"-->
                                    <!--:load="loadNode"-->
                                    <!--highlight-current-->
                                    <!--lazy-->
                                    <!--@node-click="handleNodeClick"-->
                                    <!--@node-expand="handleNodeClick"-->
                                    <!--ref="tree"-->
                                    <!--node-key="id">-->

                            <!--</el-tree>-->
                        <!--</el-option>-->
                    <!--</el-select>-->
                </el-form-item>
                <el-form-item label="IMEI" class="limit-width active" prop="code">
                    <el-input v-model="form.code"></el-input>
                </el-form-item >
                <el-form-item label="设备名称" class="limit-width active" prop="name">
                    <el-input class="el_input form_wid"  v-model="form.name"></el-input>
                </el-form-item >
                <el-form-item label="产品序号" class="limit-width active" prop="order">
                    <el-input class="el_input form_wid"  v-model="form.order" prop="order"></el-input>
                </el-form-item>
                <el-form-item label="网关" class="limit-width active" prop="concentrator">
                    <el-select v-model="form.concentrator"  placeholder="请选择" >
                        <el-option
                                v-for="item in selectConcentrator"
                                :key="item.deviceId"
                                :label="item.deviceName"
                                :value="parseInt(item.deviceId)">

                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="设备类型" class="limit-width active" prop="type" >
                    <el-select v-model="form.type"  placeholder="请选择">
                        <el-option
                                v-for="item in selectType"
                                :key="item.typeId"
                                :label="item.typeName"
                                :value="parseInt(item.typeId)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="设备组" class="limit-width active" prop="equipmentGroup">
                    <el-select v-model="form.equipmentGroup"  placeholder="请选择">
                        <el-option
                                v-for="item in selectEqimentGroup"
                                :key="item.id"
                                :label="item.groupName"
                                :value="parseInt(item.id)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="能源来源" class="limit-width active" prop="energyource">
                    <el-select v-model="form.energyource"  placeholder="请选择">
                        <el-option
                                v-for="item in selectEnergySource"
                                :key="item.value"
                                :label="item.name"
                                :value="parseInt(item.value)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="能耗类型" class="limit-width active" prop="energType">
                    <el-select v-model="form.energType"  placeholder="请选择">
                        <el-option
                                v-for="item in selectenergType"
                                :key="item.id"
                                :label="item.name"
                                :value="parseInt(item.id)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="设备状态" class="limit-width active" prop="equimentState">
                    <el-select v-model="form.equimentState"   placeholder="请选择">
                        <el-option
                                v-for="item in selectEquimentState"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="seachVisible = false">取 消</el-button>
                <el-button type="primary" @click="getResult">确 定</el-button>
            </span>
        </el-dialog>
        <!--启用-->
        <el-dialog :title="diologTitle" :close-on-click-modal="$modelGolbParam.closeOnClickModal"
                   :close-on-press-escape="$modelGolbParam.closeOnPressEscape" :visible.sync="enableVisible" width="20%" >
                    <span>确定启用当前信息吗？</span>
            <span slot="footer" class="dialog-footer">
            <el-button @click="enableVisible = false">取 消</el-button>
            <el-button type="primary" @click="getEnable">确 定</el-button>
            </span>
        </el-dialog>
        <!--禁用-->
        <el-dialog :title="diologTitle" :close-on-click-modal="$modelGolbParam.closeOnClickModal"
                   :close-on-press-escape="$modelGolbParam.closeOnPressEscape" :visible.sync="disEnablEnableVisible" width="20%" >
            <span>确定禁用当前信息吗？</span>
            <span slot="footer" class="dialog-footer">
            <el-button @click="disEnablEnableVisible = false">取 消</el-button>
            <el-button type="primary" @click="getDisEnable">确 定</el-button>
            </span>
        </el-dialog>
        <!--删除-->
        <el-dialog :title="diologTitle" :close-on-click-modal="$modelGolbParam.closeOnClickModal"
                   :close-on-press-escape="$modelGolbParam.closeOnPressEscape" :visible.sync="dieleteVisible" width="20%" >
            <span>确定删除当前信息吗？</span>
            <span slot="footer" class="dialog-footer">
            <el-button @click="dieleteVisible = false">取 消</el-button>
            <el-button type="primary" @click="getDelete()">确 定</el-button>
            </span>
        </el-dialog>
        <!--        中继选择-->
        <el-dialog title="选择中继链路" :close-on-click-modal="$modelGolbParam.closeOnClickModal"
                   :close-on-press-escape="$modelGolbParam.closeOnPressEscape" :visible.sync="isConfigMid" width="30%">
            <div>
                <template>
                    <span>中继链路名称：</span>
                    <el-select v-model="configMidData" placeholder="请选择">
                        <el-option
                                v-for="item in configMidDataList"
                                :key="item.id"
                                :label="item.repeaterName"
                                :value="item.id" style="padding-left: 15px;">
                        </el-option>
                    </el-select>
                </template>
            </div>

            <span slot="footer" class="dialog-footer">
                <el-button @click="isConfigMid = false">取 消</el-button>
                <el-button type="primary" @click="savaConfig">确 定</el-button>
            </span>
        </el-dialog>

        <!--数据补录-->
        <el-dialog title="数据补录" :close-on-click-modal="$modelGolbParam.closeOnClickModal"
                   :close-on-press-escape="$modelGolbParam.closeOnPressEscape" :visible.sync="isReInputVisible" width="70%">
            <el-form :model="form"  ref="Form" label-width="120px" class="limit-small" :rules="rules">
                <el-form-item label="补录类型" class="limit-width active" prop="concentrator">
                    <el-select v-model="reInputParams.dataType"  placeholder="请选择" >
                        <el-option
                                v-for="item in dateType"
                                :key="item.value"
                                :label="item.label"
                                :value="parseInt(item.value)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="能耗类型" class="limit-width active" prop="type" >
                    <el-select v-model="reInputParams.energyCode"  placeholder="请选择">
                        <el-option
                                v-for="item in selectenergType"
                                :key="item.id"
                                :label="item.name"
                                :value="parseInt(item.id)">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="补录时间" class="limit-width active" prop="equipmentGroup">
                    <el-date-picker
                            v-model="reInputParams.recordDate"
                            :type="reInputParams.dataType==0?'date':reInputParams.dataType==1?'month':'year'"
                            value-format="yyyy-MM-dd"
                            placeholder="请选择">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="补录数据" class="limit-width active" prop="energyource">
                    <el-input v-model="reInputParams.energyVal"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="isReInputVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveInputData">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import { regionalRoot,getSubOrgList,getDeviceTypeList,searchAll,addDevice,getAllCollector,getCategory,getGroupList,dynamicSerachDeviceInfo,deleteDevice,getRepeaterLinkList,updateDevice,batchDevices,getDeviceTypeDataConfig,getDeviceTypeDataConfigByDeviceId,getBaseEnergyTypeListNews,getEnergyConcretTypeByEnergyBaseTypeId,getDeviceDataParaByDeviceTypeId,BatchUpdateSameTypeDevice,saveInputDataRecord} from '../../../api/index';
    import {regNumber,regNumStr} from '../../common/com'
    export default {
        name: "EquipmentManagement",
        data() {
            return {
                cur_page: 1,
                page_size: 100,
                page_total: 1,
                props: {
                    label: 'orgName',
                    children: 'zones',
                    isLeaf: 'leaf'
                },
                selectType: [],//获取设备类型的下拉
                selectConcentrator: [],//获取网关下拉
                selectEqimentGroup: [],//设备组
                selectEnergySource: [],//能源来源
                selectenergType:[],//能耗类型
                selectEquimentState: [
                    {
                        value: '0',
                        label: '启用'
                    },
                    {
                        value: '1',
                        label: '禁用'
                    },
                ],
                tableData: [],//列表数据
                tagsList: [],//树菜单数据
                demoData: '',
                clickedId: '',
                bangData:[],
                lazyInitData: [],
                lazyNode: null,
                lazyResolve: null,
                addVisible: false,//新增
                isEditInfo: false,//修改
                isEditInfoAll:false,//批量修改
                enableVisible:false,//启用
                disEnablEnableVisible:false,//禁用
                dieleteVisible:false,//删除
                seachVisible: false,//高级搜索
                diologTitle: '新增',
                treeData:[],//高级查询组织机构下拉
                form: {
                    organ: '',//组织机构
                    id: '',
                    code:'',//设备编号
                    name: '',//设备名称
                    order: '',//序号
                    type: '',//设备类型
                    concentrator: '',//网关
                    equipmentGroup: '',//设备组
                    energyource: '',//能源来源
                    energType:'',//能耗类型
                    equimentState: '',//设备状态
                    address: '',//设备地址
                },
                multipleSelection: [],//当前行
                rules:{
                    // organ :[{required: true, message: '请输入', trigger: 'blur'}],
                    // id :[{required: true, message: '请输入', trigger: 'blur'}],
                    // name :[{required: true, message: '请输入', trigger: 'blur'}],
                    // order :[{required: true, message: '请输入', trigger: 'blur'}],
                    // type :[{required: true, message: '请输入', trigger: 'blur'}],
                    // concentrator :[{required: true, message: '请输入', trigger: 'blur'}],
                    // equipmentGroup :[{required: true, message: '请输入', trigger: 'blur'}],
                    // energyource :[{required: true, message: '请输入', trigger: 'blur'}],
                    // energType:[{required: true, message: '请输入', trigger: 'blur'}],
                    // equimentState :[{required: true, message: '请输入', trigger: 'blur'}],
                    // address :[{required: true, message: '请输入', trigger: 'blur'}],
                },
                isConfigMid:false,
                configMidDataList: [],
                configMidData: '',
                dataConfigTable:[
                    // {
                    //     name:'A项电压',
                    //     unit:'伏',
                    //     tableCode:'0001',
                    //     minAndMax:'9999',
                    //     feelEq:'200',
                    //     initData:'0',
                    //     warmLimt:'0',
                    //     warmHighLimt:'99999',
                    //     other:'99999',
                    // }
                ],
                configEnergyRatio:[],//能耗配置比例
                isReInputVisible:false,
                dateType: [{
                    value: '0',
                    label: '日'
                }, {
                    value: '1',
                    label: '月'
                }, {
                    value: '2',
                    label: '年'
                }],
                reInputParams:{
                    dataType: '',
                    energyCode: '',
                    deviceId: '',
                    orgId: '',
                    gourpId:'',
                    recordDate: '',
                    energyVal: ''
                }
            }

        },

        created() {
            this.getData();
            this.getMidData();//获取中继器列表
        },
        methods: {
            //设备状态格式化
            formmaterStatas(row, column, cellValue){
                for (var i=0;i<this.selectEquimentState.length;i++){
                    if(cellValue == this.selectEquimentState[i].value){
                        return this.selectEquimentState[i].label
                    }
                }
            },
            formatRation(row, column, cellValue){
                // console.log(cellValue)
                if(cellValue.length>0){
                    var cellStr = '';
                    for(var i=0;i<cellValue.length;i++){
                        cellStr += cellValue[i].dataName + ':' + cellValue[i].dataRatio + ','
                    }
                    return cellStr;
                }else{
                    return '';
                }
            },
            // //网关selectConcentrator
            // formaterConcentrator(row, column, cellValue){
            //     for (var i=0;i<this.selectConcentrator.length;i++){
            //         if (cellValue == this.selectConcentrator[i].value){
            //             return this.selectConcentrator[i].label
            //         }
            //     }
            // },
            // //设备组selectEqimentGroup
            // formEqGroup(row,column,cellValue){
            //   for (var i =0;i<this.selectEqimentGroup.length;i++){
            //       if (cellValue ==this.selectEqimentGroup[i].value){
            //           return this.selectEqimentGroup[i].label
            //       }
            //   }
            // },
            // //能耗类型selectenergType
            // formaterEnergType(row,column,cellValue){
            //     for (var i =0;i<this.selectenergType.length;i++) {
            //         if (cellValue == this.selectenergType[i].value) {
            //             return this.selectenergType[i].label
            //         }
            //     }
            // },
            // //能耗来源selectEnergySource
            // formmaterEnergySource(row,column,cellValue){
            //     for (var i=0;i<this.selectEnergySource.length;i++){
            //         if(cellValue ==this.selectEnergySource[i].value){
            //             return this.selectEnergySource[i].label
            //         }
            //     }
            // },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            // 分页导航
            handleCurrentChange(val) {
                this.cur_page = val;
                this.seach();//点击分页获取数据
            },
            //延迟加载
            loadNode(node, resolve) {
                this.lazyNode = node;
                this.lazyResolve = resolve;
                if (node.level === 0) {
                    return resolve(this.tagsList);
                }
                setTimeout(() => {
                    console.log(this.clickedId)
                    getSubOrgList({
                        pid:this.clickedId
                    }).then((res)=>{
                        console.log(res)
                        this.lazyInitData = res.datas;
                        resolve(this.lazyInitData);
                        console.log(this.lazyInitData)
                    })
                }, 500);
            },
            //选中行
            handleSelectionChange(val) {
                this.multipleSelection = val;
                console.log(this.multipleSelection)
            },
            //点击组织结构列表获取表格列表内容
            handleNodeClicks(data,node) {
                console.log(data);
                this.form.organ = data.orgFullName;
                if(data.pid === 0){
                    this.clickedId = data.id;
                    this.demoData = data;
                    this.demoData['pname'] = data.orgName;
                    this.cur_page = 1;
                    this.seach();
                    return ;
                }
                this.clickedId = data.id;
                this.demoData = data;
                this.demoData['pname'] = node.parent.data.orgName;
                console.log(this.demoData)
                this.cur_page = 1;
               this.seach();
            },
            handleNodeClick(data,node) {
                console.log(data);
                this.form.organ = data.orgFullName;
                if(data.pid === 0){
                    this.clickedId = data.id;
                    this.demoData = data;
                    this.demoData['pname'] = data.orgName;
                    return ;
                }
                this.clickedId = data.id;
                this.demoData = data;
                this.demoData['pname'] = node.parent.data.orgName;
                console.log(this.demoData)
                this.form.address = this.demoData.orgFullName,//设备地址
                this.cur_page = 1;
            },
             //获取数据以及分页
            getMidData(){

                getRepeaterLinkList({

                }).then((res) =>{
                    console.log(res)
                    this.configMidDataList = res.datas;
                })
            },
            //点击新增中继器
            configMid(v){
                if(this.multipleSelection.length < 1){
                    this.$message.error('请选择需要修改的设备');
                    return ;
                }

                clearInterval(this.setTimer);
                this.setTimer = null;

                if(v&&v=='-1'){
                    var addCountId = new Array();
                    for(var i=0;i<this.multipleSelection.length;i++){
                        addCountId.push(this.multipleSelection[i].deviceId)
                    }
                    batchDevices({
                        // cId:this.multipleSelection[0].deviceId,
                        ids:addCountId,
                        repeaterId:'-1'
                    }).then((res)=>{
                        if(res.success){
                            this.$message.success(res.message);
                            this.seach();
                        }else{
                            this.$message.error(res.message);
                        }
                    })
                    return ;
                }
                this.isConfigMid = true;
            },
            savaConfig(){
                console.log(this.multipleSelection[0]);
                console.log(this.configMidData);
                var addCountId = new Array();
                for(var i=0;i<this.multipleSelection.length;i++){
                    addCountId.push(this.multipleSelection[i].deviceId)
                }
                console.log(addCountId);
                batchDevices({
                    // cId:this.multipleSelection[0].deviceId,
                    ids:addCountId,
                    repeaterId:this.configMidData
                }).then((res)=>{
                    if(res.success){
                        this.isConfigMid = false;
                        this.$message.success(res.message);
                        this.seach();
                    }else{
                        this.$message.error(res.message);
                    }
                })


            },
            //获取组织结构数据
            getData(){
                regionalRoot({
                }).then((res) =>{
                    console.log(res)
                    var dataArr = new Array();
                    dataArr[0] = res.expandData.root;
                    this.form.organ = res.expandData.root.orgFullName;
                    console.log(this.form.organ)
                    dataArr[0]['children'] = res.expandData.childrens;
                    this.treeData=res.expandData.childrens;
                    console.log(this.treeData)
                    this.tagsList = dataArr;
                    this.clickedId = this.tagsList[0].id;
                    console.log(res.expandData.childrens)
                })
            },
            //获取设备类型下拉数据
            getDeviceTypeOne(){
                getDeviceTypeList({
                }).then((res) =>{
                    console.log(res.datas)
                    this.selectType =res.datas;
                    console.log(this.selectType)
                })
            },
            //获取网关下拉
            getAllCollectorType(){
                getAllCollector({
                }).then((res) =>{
                    console.log(res)
                    this.selectConcentrator =res.datas;
                    console.log(this.selectConcentrator)
                })
            },
            //获取能源来源
            getEnergySource(){
                getCategory({
                    "dicName":"能源来源"
                }).then((res) =>{
                    console.log(res)
                    this.selectEnergySource =res.expandData;
                    console.log(this.selectEnergySource)
                })
            },
            //获取能耗类型
            getEnergyType(){
                getBaseEnergyTypeListNews({
                    // "dicName":"能耗类型"
                }).then((res) =>{
                    console.log(res)
                    // this.selectenergType =res.expandData;
                    this.selectenergType =res;
                    console.log(this.selectenergType)
                })
            },
            //点击切换能耗类型
            handleEnergyType(){
                this.getEnergyConcretTypeByEnergyBaseTypeId(this.form.energType)
            },
            //获取能耗比例配置
            getEnergyConcretTypeByEnergyBaseTypeId(energyBaseId){
                getEnergyConcretTypeByEnergyBaseTypeId({
                    energyBaseId:energyBaseId
                }).then(res => {
                    console.log(res)
                    this.configEnergyRatio = res
                })
            },
            //获取设备组下拉
            getGroup(){
                getGroupList({
                }).then((res) =>{
                    console.log(res)
                    this.selectEqimentGroup =res.datas;
                    console.log(this.selectEqimentGroup)
                })
            },
            //获取组织结构子项数据
            getSubOrgList(){
                getSubOrgList({

                }).then((res) =>{
                    console.log(res)
                    this.tagsList.root=res.expandData.root;
                     this.tagsList.children=res.expandData.childrens;
                    var dataArr = new Array();
                    dataArr[0] = res.expandData.root;
                    dataArr[0]['children'] = res.expandData.childrens;
                    this.tagsList = dataArr;

                    this.clickedId = this.tagsList[0].id;
                    console.log(dataArr)
                })
            },
            //点击查询
            seach(){
                searchAll({
                    pageNum:this.cur_page,
                    pageSize:this.page_size,
                    "orgId":this.demoData?this.demoData.id:this.multipleSelection[0].orgId,
                }).then((res) => {
                    console.log(res)
                    this.tableData = res.data.list;
                    this.page_total = res.data.total;
                    // console.log(this.tableData)
                })
            },
            //点击保存
            save(){
                // console.log(this.dataConfigTable)
                // return ;
                if(this.isEditInfoAll){
                    this.saveEquimentAllData();
                    return ;
                }
                // if(this.configEnergyRatio&&this.configEnergyRatio.length>0){
                //     //验证配置比例的和不能大于100%
                //     var radioMax = 0 ;
                //     for(var i=0;i<this.configEnergyRatio.length;i++){
                //         radioMax += parseInt(this.configEnergyRatio[i].percentData);
                //     }
                //     console.log(this.configEnergyRatio)
                //     console.log(radioMax)
                //     if(isNaN(radioMax)){
                //         this.$message.error('能耗比例需是0-100的数字')
                //         return ;
                //     }
                //     if(radioMax!=100){
                //         this.$message.error('能耗比例之和需为100')
                //         return ;
                //     }
                // }

                console.log('1',this.formValidate(this.form));
                if (this.formValidate(this.form)) {
                    if(this.isEditInfo){
                        console.log(3,this.form)
                        updateDevice({
                                "deviceId":this.multipleSelection[0].deviceId,
                                "deviceName":this.form.name,//设备名称
                                "deviceLocation":this.demoData?this.demoData.orgFullName:this.multipleSelection[0].deviceLocation,//设备地址
                                "deviceCode":this.form.code,//设备编号
                                "deviceNo":this.form.order,//设备序号
                                "orgId":this.demoData?this.demoData.id:this.multipleSelection[0].orgId,//父节点ID
                                "energyDic":this.form.energyource,//能源来源
                                "energyTypeId":this.form.energType,//能耗类型
                                "deviceUsingState":this.form.equimentState,//状态
                                "concentrator":this.form.concentrator,//集中器
                                "groupId":this.form.equipmentGroup,//设备组
                                "typeId":this.form.type,//设备类型
                                "dataPara":this.dataConfigTable,//数据项
                                "energyConcreteType":this.configEnergyRatio//能耗比例
                         }).then((res) => {
                             if (res.success){
                                 console.log(res)
                                 this.addVisible =false;
                                 this.$message.success('修改成功')
                                 // console.log(this.demoData?this.demoData.id:this.multipleSelection[0].orgId)
                                 this.seach();
                             }else{
                                 this.$message.error(res.message);
                            }

                        })
                         return;
                    }
                    //新增接口调用
                    console.log(2,this.form);
                    addDevice({
                        "deviceName":this.form.name,//设备名称
                        "deviceLocation":this.demoData.orgFullName,//设备地址
                        "deviceCode":this.form.code,//设备编号
                        "deviceNo":this.form.order,//设备序号
                        "orgId":this.demoData.id,//父节点ID
                        "energyDic":this.form.energyource,//能源来源
                        "energyTypeId":this.form.energType,//能耗类型
                        "deviceUsingState":this.form.equimentState,//状态
                        "concentrator":this.form.concentrator,//集中器
                        "groupId":this.form.equipmentGroup,//设备组
                       "typeId":this.form.type,//设备类型
                        "dataPara":this.dataConfigTable,//数据项
                        "energyConcreteType":this.configEnergyRatio//能耗比例
                    }).then((res) => {
                        console.log(this.form)
                        if (res.success) {
                            console.log(res)
                            this.addVisible = false;
                            this.$message.success(`添加成功`);
                            this.seach(this.demoData.id);
                        } else {
                            this.$message.error(res.message);
                        }
                    })
                }
            },
            //高级搜索接口调用
                getResult(){
                    this.cur_page = 1;
                    dynamicSerachDeviceInfo(
                        {
                            pageNum:this.cur_page,
                            pageSize:this.page_size,
                        "deviceName":this.form.name?this.form.name:null,//设备名称
                        // "deviceLocation":this.demoData?this.demoData.orgFullName:this.tagsList[0].orgFullName,//设备地址
                         "deviceLocation":this.form.address?this.form.address:null,
                        "deviceCode":this.form.code?this.form.code:null,//设备编号
                        "deviceNo":this.form.order?this.form.order:null,//设备序号
                        // "orgId":this.demoData?this.demoData.id:this.tagsList[0].id,//父节点ID
                        "energyDic":this.form.energyource?this.form.energyource:null,//能源来源 energyource
                        "energyTypeId":this.form.energType?this.form.energType:null,//能耗类型
                        "deviceUsingState":this.form.equimentState?this.form.equimentState:null,//状态
                        "concentrator":this.form.concentrator?this.form.concentrator:null,//集中器
                        "groupId":this.form.equipmentGroup?this.form.equipmentGroup:null,//设备组
                        "typeId":this.form.type?this.form.type:null,//设备类型
                    }).then((res) =>{
                        if (res.success){
                            console.log(res)
                            console.log(res.data)
                            console.log(res.data.list)
                            this.seachVisible=false;
                            this.$message.success(`查询成功`);
                            this.tableData =res.data.list;
                            this.page_total = res.data.total;
                        }else {
                            this.$message.error(res.message);
                        }
                    })
                },
            //启用接口调用
            getEnable(){
                var allEquimentList = this.multipleSelection;
                var multDeviceIds = [];
                var multParams = {};
                for(var i=0;i<allEquimentList.length;i++){
                    multDeviceIds.push(allEquimentList[i].deviceId)
                }
                multParams['deviceUsingState'] = '0';
                multParams['deviceIds'] = multDeviceIds;
                BatchUpdateSameTypeDevice(multParams).then(res=>{
                    if (res.success){
                        console.log(res)
                        this.enableVisible =false;
                        this.$message.success('启用成功')
                        this.seach();
                    }else{
                        this.$message.error(res.message);
                    }
                })

                // if (this.multipleSelection[0].deviceUsingState == 0){
                //     this.$message.success('当前已经是启用状态')
                //     setTimeout(() => {
                //         this.enableVisible =false;
                //     }, 500);
                //     return;
                // }
                // if (this.multipleSelection[0].deviceUsingState == 1){
                //     updateDevice({
                //         "deviceId":this.multipleSelection[0].deviceId,
                //         "deviceUsingState":0,
                //         'concentrator':this.multipleSelection[0].concentrator,//集中器
                //         "deviceCode":this.multipleSelection[0].deviceCode,//设备编号
                //         "deviceName":this.multipleSelection[0].deviceName,//设备名称
                //         'deviceNo':this.multipleSelection[0].deviceNo,//设备序号
                //         'energyDic':this.multipleSelection[0].energyDic,//能源来源
                //         'energyTypeId':this.multipleSelection[0].energyTypeId,//能耗类型
                //         "typeId":this.multipleSelection[0].typeId,//设备类型
                //         "groupId":this.multipleSelection[0].groupId,//设备组
                //     }).then((res) =>{
                //         console.log(res)
                //         if(res.success){
                //             this.enableVisible =false;
                //             this.$message.success('启用成功')
                //             this.seach(this.demoData.id)
                //         }
                //         else{
                //             this.$message.error('启用失败')
                //         }
                //     })
                // }

            },
            //禁用接口调用
            getDisEnable(){
                var allEquimentList = this.multipleSelection;
                var multDeviceIds = [];
                var multParams = {};
                for(var i=0;i<allEquimentList.length;i++){
                    multDeviceIds.push(allEquimentList[i].deviceId)
                }
                multParams['deviceUsingState'] = '1';
                multParams['deviceIds'] = multDeviceIds;
                BatchUpdateSameTypeDevice(multParams).then(res=>{
                    if (res.success){
                        console.log(res)
                        this.disEnablEnableVisible =false;
                        this.$message.success('禁用成功')
                        this.seach();
                    }else{
                        this.$message.error(res.message);
                    }
                })

                // if (this.multipleSelection[0].deviceUsingState == 1){
                //     this.$message.success('当前已经是禁用状态')
                //     setTimeout(() => {
                //         this.disEnablEnableVisible =false;
                //     }, 500);
                //     return;
                // }
                // if (this.multipleSelection[0].deviceUsingState == 0){
                //     updateDevice({
                //         "deviceId":this.multipleSelection[0].deviceId,
                //         "deviceUsingState":1,
                //         'concentrator':this.multipleSelection[0].concentrator,//集中器
                //         "deviceCode":this.multipleSelection[0].deviceCode,//设备编号
                //         "deviceName":this.multipleSelection[0].deviceName,//设备名称
                //         'deviceNo':this.multipleSelection[0].deviceNo,//设备序号
                //         'energyDic':this.multipleSelection[0].energyDic,//能源来源
                //         'energyTypeId':this.multipleSelection[0].energyTypeId,//能耗类型
                //         "typeId":this.multipleSelection[0].typeId,//设备类型
                //         "groupId":this.multipleSelection[0].groupId,//设备组
                //     }).then((res)=>{
                //         console.log(res)
                //         if(res.success){
                //             this.disEnablEnableVisible =false;
                //             this.$message.success('禁用成功')
                //             this.seach(this.demoData.id)
                //         }
                //         else{
                //             this.$message.error('禁用失败')
                //         }
                //     })
                // }

            },
            //删除接口调用
            getDelete(){
                deleteDevice({
                    id:this.multipleSelection[0].deviceId,
                }).then((res)=>{
                    console.log(res)
                    if(res.success){
                        this.$message.success('删除成功');
                        this.dieleteVisible = false;
                        this.seach(this.demoData.id);
                    }else{
                        this.$message.error(res.message)
                    }
                })
            },
            //新增弹出框
            addEquiment(){
                this.dataConfigTable = [];
                this.configEnergyRatio = [];
                this.addVisible = true;
                this.isEditInfo =false;
                this.isEditInfoAll = false;
                this.diologTitle = '新增设备';
                console.log(this.lazyInitData)
                this.form = {
                    organ:this.demoData.orgName,//组织名称
                    name:'',//设备名称
                    code:'',//编码
                    order:'',//序号
                    concentrator:'',//网关
                    equipmentGroup:'',//设备组
                    energyource:'',//能源来源
                    energType:'',//能耗类型
                    equimentState:'0',//设备状态
                    address:this.demoData.orgFullName,//设备地址
                },
                    this.getDeviceTypeOne();//获取设备类型的下拉
                    this.getAllCollectorType();//获取网关下拉
                    this.getEnergySource();//获取能源来源
                    this.getEnergyType();//或取能耗来源
                   this.getGroup();//设备组
            },
            //高级查询弹窗
            seachEquiment(){
                this.seachVisible = true;
                // this.isEditInfo =false;
                this.diologTitle = '设备查询';
                this.form = {
                    organ:this.tagsList[0].orgFullName,//组织名称
                    name:'',//设备名称
                    code:'',//编码
                    order:'',//序号
                    concentrator:'',//网关
                    equipmentGroup:'',//设备组
                    energyource:'',//能源来源
                    energType:'',//能耗类型
                    equimentState:'',//设备状态
                    address:this.demoData.orgFullName,//设备地址
                }
                this.getDeviceTypeOne();//获取设备类型的下拉
                this.getAllCollectorType();//获取网关下拉
                this.getEnergySource();//获取能源来源
                this.getEnergyType();//或取能耗来源
                this.getGroup();//设备组
            },
            //修改弹窗
            editEquiment() {
                if (this.multipleSelection.length < 1) {
                    this.$message.error('请选择需要修改的设备');
                } else if (this.multipleSelection.length == 1) {
                    this.dataConfigTable = [];
                    // this.getDeviceTypeDataConfigByDeviceId();//获取设备数据项
                    this.getDeviceTypeOne();//获取设备类型的下拉
                    this.getAllCollectorType();//获取网关下拉
                    this.getEnergySource();//获取能源来源
                    this.getEnergyType();//或取能耗来源
                    this.getGroup();//设备组
                    console.log(this.multipleSelection)
                    this.diologTitle = '修改设备';
                    this.addVisible = true;
                    this.isEditInfo = true;
                    this.isEditInfoAll = false;
                    this.demoData = '' ;
                    this.form={
                        organ:this.multipleSelection[0].deviceLocation,//组织机构
                        name:this.multipleSelection[0].deviceName,//设备名称
                        address:this.multipleSelection[0].deviceLocation,//组织机构
                        code:this.multipleSelection[0].deviceCode,//设备编号
                        order:this.multipleSelection[0].deviceNo,//设备序号
                        concentrator:this.multipleSelection[0].concentrator,//集中器
                        equipmentGroup:this.multipleSelection[0].groupId,//设备组
                        energyource:this.multipleSelection[0].energyDic,//能源来源
                        energType:this.multipleSelection[0].energyTypeId,//能耗类型
                        equimentState:this.multipleSelection[0].deviceUsingState,//设备状态
                        type:this.multipleSelection[0].typeId//设备类型
                    }
                    this.dataConfigTable = this.multipleSelection[0].dataPara
                    this.configEnergyRatio = this.multipleSelection[0].energyRatio
                } else {
                    this.$message.error('一次只能修改一个设备');
                }
            },
            //删除弹窗
            deleteAble(){
                if(this.multipleSelection.length < 1){
                    this.$message.error('请选择需要删除的设备');
                }else
                if(this.multipleSelection.length == 1){
                    this.diologTitle='设备删除';
                    this.dieleteVisible=true;
                }else{
                    this.$message.error('一次只能修删除一条数据');
                }
            },
            //启用弹窗
            enable(){
                if (this.multipleSelection.length < 1) {
                    this.$message.error('请选择需要启用的设备');
                    return ;
                }
                this.diologTitle = '设备启用';
                this.enableVisible=true;

                // if (this.multipleSelection.length < 1) {
                //     this.$message.error('请选择需要启用的设备');
                // } else if (this.multipleSelection.length > 1) {
                //     this.$message.error('一次只能启用一条设备')
                // } else {
                //     this.diologTitle = '设备启用';
                //     this.enableVisible=true;
                // }
            },
            //禁用弹窗
            disEnable(){
                if (this.multipleSelection.length < 1) {
                    this.$message.error('请选择需要禁用的设备');
                    return ;
                }
                this.diologTitle = '设备禁用';
                this.disEnablEnableVisible =true;
                // if (this.multipleSelection.length < 1) {
                //     this.$message.error('请选择需要禁用的设备');
                // } else if (this.multipleSelection.length > 1) {
                //     this.$message.error('一次只能禁用一条设备')
                //
                // } else {
                //     this.diologTitle = '设备禁用';
                //     this.disEnablEnableVisible =true;
                // }
            },
            //验证
            formValidate(formname) {
                console.log(4,formname)
                // formname.organ && && formname.energType && formname.address &&
                // formname.equipmentGroup && formname.energyource  && formname.equimentState
                // if ( formname.code && formname.name && formname.order && formname.concentrator && formname.type  )
                if ( formname.code && formname.name && formname.type  ) {
                    if (!regNumStr(formname.code) || !regNumber(formname.code)) {
                        this.$message.error('IMEI只能为数字或者是数字和字母的组合');
                        return false;
                    }
                    return true;
                } else {
                    // if (!formname.organ) {
                    //     this.$message.error('请选择组织机构');
                    //     return false;
                    // }
                    if (!formname.code) {
                        this.$message.error('请输入IMEI号');
                        return false;
                    }
                    if (!formname.name) {
                        this.$message.error('请输入设备名称');
                        return false;
                    }
                    // if (!formname.order) {
                    //     this.$message.error('请输入设备序号');
                    //     return false;
                    // }
                    // if (!formname.concentrator) {
                    //     this.$message.error('请选择网关');
                    //     return false;
                    // }
                    if (!formname.type) {
                        this.$message.error('请选择设备类型');
                        return false;
                    }
                    // if (!formname.equipmentGroup) {
                    //     this.$message.error('请选择设备组');
                    //     return false;
                    // }
                    // if (!formname.energyource) {
                    //     this.$message.error('请选择能源来源');
                    //     return false;
                    // }
                    // if (!formname.energType) {
                    //     this.$message.error('请选择能耗类型');
                    //     return false;
                    // }
                    // if (!formname.equimentState) {
                    //     this.$message.error('请选择设备状态');
                    //     return false;
                    // }
                    // if (!formname.address) {
                    //     this.$message.error('请输入设备地址');
                    //     return false;
                    // }
                }
            },
            selectedDeviceType(val){
                this.dataConfigTable = [];
                getDeviceDataParaByDeviceTypeId({
                    deviceTypeId:val
                }).then(res => {
                    console.log(res)
                    this.dataConfigTable = res;
                })

                //旧接口暂留
                // getDeviceTypeDataConfig({
                //     deviceTypeId:val
                // }).then((res)=>{
                //     console.log(res);
                //     if(res.length>1){
                //         var resData = res;
                //         for(var i=0;i<resData.length;i++){
                //             resData[i]['dataInitialValue'] = '';
                //             resData[i]['virtualCode'] = '';
                //         }
                //         this.dataConfigTable = resData;
                //     }else{
                //         this.dataConfigTable = res;
                //     }
                //
                // })
                //通过设备id获取设备数据项
                // if(this.isEditInfo && val == this.multipleSelection[0].typeId){
                //     this.getDeviceTypeDataConfigByDeviceId();
                // }
            },
            getDeviceTypeDataConfigByDeviceId(){
                getDeviceTypeDataConfigByDeviceId({
                    deviceId:this.multipleSelection[0].deviceId
                }).then((res)=>{
                    this.dataConfigTable = res;
                })
            },
            //点击批量修改
            editEquimentAll(){
                if (this.multipleSelection.length < 1) {
                    this.$message.error('请选择需要修改的设备');
                    return ;
                }
                this.form = {
                        organ: '',//组织机构
                        id: '',
                        code:'',//设备编号
                        name: '',//设备名称
                        order: '',//序号
                        type: '',//设备类型
                        concentrator: '',//网关
                        equipmentGroup: '',//设备组
                        energyource: '',//能源来源
                        energType:'',//能耗类型
                        equimentState: '',//设备状态
                        address: '',//设备地址
                };
                this.demoData = '' ;
                // this.getDeviceTypeDataConfigByDeviceId();//获取设备数据项
                this.getDeviceTypeOne();//获取设备类型的下拉
                this.getAllCollectorType();//获取网关下拉
                this.getEnergySource();//获取能源来源
                this.getEnergyType();//或取能耗来源
                this.getGroup();//设备组
                this.diologTitle = '批量修改';
                this.isEditInfoAll = true;
                this.addVisible = true;
                this.dataConfigTable = [];
                this.configEnergyRatio = [];
            },
            //批量修改保存数据
            saveEquimentAllData(){

                var postAllData = {
                    "deviceLocation":this.demoData.orgFullName,//设备地址
                    "orgId":this.demoData.id,//父节点ID
                    "energyDic":this.form.energyource,//能源来源
                    "energyTypeId":this.form.energType,//能耗类型
                    "deviceUsingState":this.form.equimentState,//状态
                    "concentrator":this.form.concentrator,//集中器
                    "groupId":this.form.equipmentGroup,//设备组
                    "typeId":this.form.type,//设备类型
                    "dataPara":this.dataConfigTable,//数据项
                }
                console.log(postAllData)
                var allEquimentList = this.multipleSelection;
                var sameTypeIdIndex = 0 ,sameTypeId = allEquimentList[0].typeId;
                for(var i=0;i<allEquimentList.length;i++){
                    if(sameTypeId == allEquimentList[i].typeId){
                        sameTypeIdIndex ++;
                    }
                }
                if(sameTypeIdIndex != allEquimentList.length){
                    this.$message.error('批量修改需是同种类的设备');
                    return ;
                }
                var multDeviceIds = [];
                var multParams = {};
                for(var i=0;i<allEquimentList.length;i++){
                    multDeviceIds.push(allEquimentList[i].deviceId)
                    // allEquimentList[i].concentrator = this.form.concentrator?this.form.concentrator:allEquimentList[i].concentrator;
                    // allEquimentList[i].groupId = this.form.equipmentGroup?this.form.equipmentGroup:allEquimentList[i].groupId;
                    // allEquimentList[i].energyTypeId = this.form.energType?this.form.energType:allEquimentList[i].energyTypeId;
                    // allEquimentList[i].deviceUsingState = this.form.equimentState?this.form.equimentState:allEquimentList[i].deviceUsingState;
                    // allEquimentList[i].typeId = this.form.type?this.form.type:allEquimentList[i].typeId;
                    // allEquimentList[i].deviceLocation = this.demoData.orgFullName?this.demoData.orgFullName:allEquimentList[i].deviceLocation;
                    // allEquimentList[i].orgId = this.demoData.id?this.demoData.id:allEquimentList[i].orgId;
                    // allEquimentList[i].dataPara = this.dataConfigTable?this.dataConfigTable:allEquimentList[i].dataPara ;
                    // allEquimentList[i].energyRatio = this.configEnergyRatio?this.configEnergyRatio:allEquimentList[i].energyRatio
                    // allEquimentList[i].energyDic = this.form.energyource?this.form.energyource:allEquimentList[i].energyDic
                }
                multParams['concentrator'] = this.form.concentrator?this.form.concentrator:null;
                multParams['groupId'] = this.form.equipmentGroup?this.form.equipmentGroup:null;
                // multParams['energyTypeId'] = this.form.energType?this.form.energType:null;
                multParams['deviceUsingState'] = this.form.equimentState?this.form.equimentState:null;
                // multParams['typeId'] = this.form.type?this.form.type:null;
                multParams['deviceLocation'] = this.demoData.orgFullName?this.demoData.orgFullName:null;
                multParams['orgId'] = this.demoData.id?this.demoData.id:null;
                // multParams['dataPara'] = this.dataConfigTable.length>0?this.dataConfigTable:null;
                // multParams['energyRatio'] = this.configEnergyRatio.length>0?this.configEnergyRatio:null;
                multParams['energyDic'] = this.form.energyource?this.form.energyource:null;
                multParams['deviceIds'] = multDeviceIds;
                // console.log(allEquimentList)
                console.log(multParams)
                BatchUpdateSameTypeDevice(multParams).then(res=>{
                    if (res.success){
                        console.log(res)
                        this.isEditInfoAll = false;
                        this.addVisible = false;
                        this.$message.success('修改成功')
                        this.seach();
                    }else{
                        this.$message.error(res.message);
                    }
                })
            },
            //数据补录
            reInput(){
                this.getEnergyType();//或取能耗来源
                this.isReInputVisible = true
            },
            saveInputData(){
                if(this.multipleSelection.length < 1){
                    this.$message.error('请选择需要补录的设备');
                }else
                if(this.multipleSelection.length == 1){
                    this.reInputParams['orgId'] = this.multipleSelection[0].orgId
                    this.reInputParams['deviceId']=this.multipleSelection[0].deviceId
                    this.reInputParams['gourpId']=this.multipleSelection[0].groupId
                    console.log('reInputParams==',this.reInputParams)
                    saveInputDataRecord(this.reInputParams).then(res=>{
                        if(res.success){
                            this.$message.success('补录成功');
                            this.isReInputVisible = false
                        }else{
                            this.$message.error(res.message)
                        }
                    })

                }else{
                    this.$message.error('一次只能选择一个设备');
                }

            }
        }
    }
</script>

<style scoped>
    /deep/ .el-form-item__content{
        margin-left: 0 !important;
    }

    /deep/ .el-form-item--small .el-form-item__content, .el-form-item--small .el-form-item__label{
        line-height: 0px;
    }
    .handle-box {
        margin-bottom: 20px;
        margin-top: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .table{
        width: 100%;
        font-size: 14px;
    }
    .red{
        color: #ff0000;
    }
    .mr10{
        margin-right: 10px;
    }
    .el-dialog{
        max-height:600px;
        overflow-y: scroll;
    }

    .el-select{
        width:60%;
    }
    .el-input{
        width:60%;
    }
    /*.limit-small .el-form-item{*/
    /*    float: left;*/
    /*    width: 50%;*/
    /*}*/
    .limit-small{
        overflow: hidden;
    }
    /*.limit-width{*/
    /*    width: 50%;*/
    /*    float: left;*/
    /*}*/
    .active{
        width: 50%;
        float: left;
    }
    /*.el-input{*/
    /*    width: 80%;*/
    /*}*/
    .el-scrollbar .el-scrollbar__view .el-select-dropdown__item{
        height: auto;
        max-height: 274px;
        padding: 0;
        overflow: hidden;
        overflow-y: auto;
    }
    .el-form-item::after, .el-form-item::before {
        clear: both;
    }
    /deep/ .no-border-input input.el-input__inner{
        border: 0;
        padding:0;

    }
    /deep/ .no-border-input {
        width: 100%;

    }
</style>
